/*
 * @Author: xiaosihan 
 * @Date: 2023-08-10 11:24:00 
 * @Last Modified by: xiaosihan
 * @Last Modified time: 2023-11-12 21:24:40
 */

import designEditor from "@/editorComponent/designEditor";
import editorStore from "@/editorComponent/editorStore";
import { Tooltip } from "antd";
import clsx from "clsx";
import { autorun } from "mobx";
import { useEffect, useRef, useState } from "react";
import leftRightConverPNG from "./leftRightConver.png";
import leftRightConverHoverPNG from "./leftRightConver_hover.png";
import styles from "./toolLeftRightCover.module.less";

interface Iprops {
}

// 宽度最大化 Alt + W
export default function ToolLeftRightCover() {

  const [hover, setHover] = useState(false);
  const [visible, setVisible] = useState(false);
  const [disable, setDisable] = useState(false);

  useEffect(() => autorun(() => {
    const { activeObjectId, lock } = editorStore;
    setDisable(lock);
    const activeObject = designEditor.fabricCanvas.getActiveObject();
    if (activeObjectId && activeObject && activeObject.type === "image") {
      setVisible(true);
    } else {
      setVisible(false);
    }
  }), []);

  return (
    <Tooltip
      title="宽度最大化(Alt + W)"
      placement="top"
      mouseLeaveDelay={0}
      mouseEnterDelay={0.5}
    >
      <div
        onClick={() => {
          designEditor.leftRightCover();
        }}
        onMouseEnter={() => {
          setHover(true);
        }}
        onMouseLeave={() => {
          setHover(false);
        }}
        className={clsx(styles.toolLeftRightCover, visible && styles.visible, disable && styles.disable)}
      >
        <img className={styles.icon} src={hover ? leftRightConverHoverPNG : leftRightConverPNG} alt="" />
      </div>
    </Tooltip>
  );

}